<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>频谱的测量</title>
    <style>
        * {
            margin: 0;
            padding :0;
        }
        body {
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            background: #6495ED;
        }
        .box {
            width: 500px;
            min-height: 300px;
            border-radius: 10px;
            background: #fff;
            padding-bottom: 30px;
            box-shadow: 0 0 5px #ddd;
        }
        h1 {
            margin-top: 20px;
            color:#333;
            width: 100%;
            text-align: center;
            line-height: 80px;
            font-size: 23px;
        }
        h2 {
            background: #6495ED;
            color: #fff;
            box-sizing: border-box;
            border-radius: 8px;
            padding-left: 10px;
            font-size: 20px;
            width: 80%;
            margin: 0 auto;
            line-height: 35px;
        }
        ul {
            width: 75%;
            margin: 0 auto;
            list-style-type: none;
            display: flex;
            flex-wrap: wrap;
        }
        li {
            color: #696969;
            margin-right: 20px;
            font-size: 20px;
            line-height: 40px;
        }
    </style>
</head>
<body>
    <div class="box">
        <h1>频谱的测量: 输入 N(dB) 得到Ux和An</h1>
        <h2>Ux</h2>
        <ul id="ux"></ul>

        <h2>An</h2>
        <ul id="an"></ul>
    </div>

    <script>
        "use strict";
        let number;
        let arr = [];
        const ux = document.getElementById("ux");
        const an = document.getElementById("an");
        number = + prompt("输入电平值，即可求得振幅\n请输入数据组数：");
        for(let i = 0; i < number; i++) {
            arr[i] = + prompt(`第${i+1}个：`);
            console.log(arr[i]);
        }
        alert("输入完毕");

        // bindStringNode(挂载父元素，节点类型（标签名），节点内容)
        function bindStringdNode(tar, type, str) {
            let textnode = document.createTextNode(str);
            let node = document.createElement(type);
            node.appendChild(textnode);
            tar.appendChild(node);
        }

        arr.forEach(( item ) => {
            let uxr = 0.775 * Math.pow(10, item/20);
            let anr = 1.414*uxr;
            bindStringdNode(ux, "li", uxr.toFixed(2));
            bindStringdNode(an, "li", anr.toFixed(2));
        });

    </script>

</body>
</html>